package com.mike.uaa.server.authentication.strategy;

import com.mike.uaa.core.Authentication;
import com.mike.uaa.core.DefaultAuthenticationToken;
import com.mike.uaa.web.ServiceException;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author z zhang
 */
@Component
public class AccountLockStrategy implements AuthenticationFailureStrategy {


    @Override
    public Authentication handleFailure(Authentication authentication, Exception exception) {
        if (exception instanceof ServiceException) {
            ServiceException se = (ServiceException) exception;
            if (Objects.equals(4011, se.getStatus())) {
                // 账号锁定逻辑
            }
        }
        return DefaultAuthenticationToken.builder().principal(exception.getMessage()).build();
    }

    @Override
    public boolean isSupport(Class<? extends Exception> exceptionClass) {
        return Exception.class.isAssignableFrom(exceptionClass);
    }
}
